package ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.fy.fyzf.R;
import com.fy.fyzf.base.BaseActivity;
import com.fy.fyzf.base.BaseFragment;
import com.fy.fyzf.base.BasePresenter;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.bean.RecordBean;
import com.fy.fyzf.bean.UserInfoBean;
import com.fy.fyzf.presenter.SelfPresenter;
import com.fy.fyzf.view.SelfInfoCallBack;
import com.google.android.material.tabs.TabLayout;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ui.fragment.IntegralStoreFragment;

public class IntegralStoreActivity extends BaseActivity<SelfPresenter> implements SelfInfoCallBack {

    @BindView(R.id.tv_jifen)
    TextView tvJifen;
    @BindView(R.id.tv_detail)
    TextView tvDetail;
    @BindView(R.id.tv_rule)
    TextView tvRule;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.rightImage)
    ImageView ivRight;

    @Override
    protected SelfPresenter createPresenter() {
        return new SelfPresenter(this);
    }
    @Override
    protected int provideContentViewId() {
        return R.layout.activity_integral_store;
    }

    @OnClick({R.id.rightImage,R.id.tv_detail, R.id.tv_rule})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rightImage:
            startActivity(new Intent(IntegralStoreActivity.this,ExChangeRecordActivity.class));
                break;
            case R.id.tv_detail:
                startActivity(new Intent(IntegralStoreActivity.this,IntegralDetailActivity.class));
                break;
            case R.id.tv_rule:
                startActivity(new Intent(IntegralStoreActivity.this,IntegralRuleActivity.class));
                break;
        }
    }
    private List<BaseFragment> fragmentList = new ArrayList<>();
    private List<String> titles = new ArrayList<>();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterEventBus(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void saveSuccess(String s) {
        if (s.equals("exchangeSuccess")) {
            initData();
        }
    }
    @Override
    public void initView() {
        super.initView();
        registerEventBus(this);
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setBackgroundResource(R.mipmap.icon_more);
        setTitleName("积分商城");
        fragmentList.add(IntegralStoreFragment.newInstance("1"));
        fragmentList.add(IntegralStoreFragment.newInstance("2"));

        titles.add("生活娱乐");
        titles.add("精品好货");

        viewpager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
                super.destroyItem(container, position, object);
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles.get(position);

            }
        });


        tablayout.setupWithViewPager(viewpager);
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.getSelfInfo();

    }

    @Override
    public void getSelfInfoSuccess(UserInfoBean userInfoBean) {
        tvJifen.setText("我的积分:"+userInfoBean.getIntegral());

    }

    @Override
    public void upLoadImgSuccess(BaseData baseData) {

    }

    @Override
    public void updataSlefInfoSuccess(BaseData baseData) {

    }

    @Override
    public void getMsgCountSuccess(BaseData baseData) {

    }

    @Override
    public void changePwdSuccess(BaseData baseData) {

    }

    @Override
    public void getChangeMsgSuccess(List<RecordBean> list) {

    }

    @Override
    public void getMyHousingSuccess(HousesListBean housesListBean) {

    }
}